package com.example.policymode4.factory;

import com.example.policymode4.AlipayPayment;
import com.example.policymode4.BankCardPayment;
import com.example.policymode4.WxPayment;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhang
 */
public class PaymentFactory {
    private static final Map<String, Payment> payStrategies = new HashMap<>();
    static {
        payStrategies.put("weixin", new WxPayment());
        payStrategies.put("alipay", new AlipayPayment());
        payStrategies.put("bankCard", new BankCardPayment());
    }

    public static Payment getPayment(String payType) {
        if (payType == null) {
            throw new IllegalArgumentException("pay type is empty.");
        }
        if (!payStrategies.containsKey(payType)) {
            throw new IllegalArgumentException("pay type not supported.");
        }
        return payStrategies.get(payType);
    }
}